import { Component, Input, OnInit } from '@angular/core';
import { AppGlobalService } from '../../shared/service/app-global.service';
import { HttpService } from './../../shared/service/http.service';
@Component({
  selector: 'app-footer-protocol',
  templateUrl: './footer-protocol.component.html',
  styleUrls: ['./footer-protocol.component.scss'],
})
// tslint:disable
export class FooterProtocolComponent implements OnInit {
  @Input() tagData: any;
  constructor(private appGlobalService: AppGlobalService, private http: HttpService) { }
  ngOnInit() { }
  gotoProtocol(obj) {
    if (obj.type === "contract") {
      const targetObj = { pageId: obj.target, params: obj.params, sessionId: localStorage.getItem('sessionId') };
      this.http.post('element/serviceContract/url', targetObj.params, res => {
        this.appGlobalService.openUrl(obj.label, res.url, obj.target, JSON.stringify(obj.params));
      });
    } else if (obj.type === "ljcontract") {
      const targetObj = { pageId: obj.target, params: obj.params, sessionId: localStorage.getItem('sessionId') };
      this.http.post('element/ljserviceContract/url', targetObj.params, res => {
        const title = obj.label ? obj.label : this.tagData.data.label;
        this.appGlobalService.openUrl(title, res.url, obj.target, JSON.stringify(obj.params));
      });
    } else if (obj.type === "decoration" || obj.type === "projectInv" || obj.type === "propertyInv") {
      const pageParams = {
        pageId: obj.target,
        params: obj.params,
        sessionId: localStorage.getItem("sessionId")
      };
      const type = { type: obj.type };
      pageParams.params = Object.assign(
        pageParams.params,
        type
      );
      this.http.post('element/serviceContract/decorationurl', pageParams.params, res => {
        this.appGlobalService.openUrl(obj.label, res.url, obj.target, JSON.stringify(obj.params));
      });
    } else if (obj.type === "page") {
      const targetObj = { pageId: obj.target, params: obj.params, sessionId: localStorage.getItem('sessionId') };
      this.appGlobalService.goToForward(targetObj);
    } else {
    }
  }
}
